<?php
    
    $userName = $_GET['userName'];
    $passWord = $_GET['passWord'];
	$age = $_GET['age'];
	$email = $_GET['email'];
	$sex = $_GET['sex'];
	$phone = $_GET['phone'];
    
	if ($userName == "") {
		echo "获取GET失败";
	    $userName = $_POST['userName'];
	    $passWord = $_POST['passWord'];
		$age = (int)$_POST['age'];
		$email = $_POST['email'];
		$sex = (int)$_POST['sex'];
		$phone = $_POST['phone'];
	}
	
    $connect = mysql_connect('localhost','root','1234');
    if($connect) {
        mysql_select_db('user_info'); //打开数据库
		$selectSql = "SELECT * from userinfo where userName = '$userName'";
		$selectResult = mysql_query($selectSql,$connect);
		if (mysql_num_rows($selectResult)) {
			echo "{\"code\":\"-1\",\"msg\":\"用户名已存在\"}";
			exit();
		}
        $sql = "INSERT INTO userinfo (userName, passWord, age, email, sex, phone) VALUES ('$userName', '$passWord', $age, '$email', $sex, '$phone')";
		$result = mysql_query($sql,$connect);
        if($result != 0)
			echo "{\"code\":\"0\",\"msg\":\"注册成功\"}";
		else
			echo "{\"code\":\"-1\",\"msg\":\"更新数据库失败\"}";
    } else {
        echo "{\"code\":\"-1\",\"msg\":\"连接数据库失败\"}";
    }
    mysql_close($connect);
?>